package com.ftg.learn.controller;

import com.ftg.learn.pojo.Xinwen;
import com.ftg.learn.service.XinwenService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


        @RestController
        @CrossOrigin
        @RequestMapping("/xinwen")
        public class XinwenController {
            @Autowired
            XinwenService xs;
            //查询全部加分页
            @GetMapping("/show")
            public Map<String,Object> showall(int page,int limit) {
                Map<String, Object> map = new HashMap<>();
                List<Xinwen> list = xs.showall(page, limit);
                map.put("data", list);
                map.put("code", 0);
                map.put("count", xs.getcount());
                map.put("msg","到哪里");
                return map;
            }
            //查一
            @PutMapping("/findone")
            public List<Xinwen> findone(String xinwen_id, String xinwen_bt){
                return xs.findone(xinwen_id,xinwen_bt);
            }
            //添加
            @PostMapping ("/add")
            public int addCar(Xinwen xinwen){
                return xs.add(xinwen);
            }
            //删除
            @DeleteMapping("/delete/{xinwen_id}")
            public int deleteCar(@PathVariable String xinwen_id){
                System.out.println(xinwen_id+"wwwwwwwwwwwwwwwwwwwww");
                return xs.delete(xinwen_id);
            }
            //修改
            @PostMapping("/update")
            public int update(Xinwen xinwen){
                System.out.println("update");
                System.out.println(xinwen.getXinwen_id());
                return xs.update(xinwen);
            }




}
